Background
I want to create a simple email viewer. That’s bec I’m using MailKit (via C# / Nuget) to download the email messages from my email server.
So, I will just accept that dependency, bec it is Nuget & feels official. So that is a rabbit-hole I won’t travel down.
NPM Rabbit-hole
I look around for a library that allows me to view the eml (email data format) files as HTML.
Cool, I find a node package which will convert eml to html. eml-parser via NPM.
View Source Code (yes, it’s JS)
You can view the bulk of the source code for this parser, here (also on the NPM site).
That doesn’t look terrible. Ok, let’s take a look at the eml-parser’s dependencies shown here (on NPM site). There are only 7 dependencies, so it can’t be that bad, right?
EML to PDF
Oh, there’s one that allows you to convert from EML directly to PDF. Let’s take a look, here (again on NPM site).
Deprecated!
Well, that package has a warning that it is deprecated and you should use puppeteer now instead.
Ignore It & Try Sample
Ok, I got it. For now I say, “forget it, let’s try a sample”.
Create Node Project
- create a quick node project
- install the eml-parser
- copy paste some sample code & voila!!
Here’s the entire program that takes test.eml and converts it to PDF & HTML.
console.log(`I'm running...`);
const EmlParser = require('eml-parser');
const fs = require('fs');
let emailFile = fs.createReadStream('./test.eml');
new EmlParser(emailFile).convertEmailToStream('pdf')
.then(stream => {
stream.pipe(fs.createWriteStream(emailFile.path + '.pdf'));
})
.catch(err => {
console.log(err);
});
new EmlParser(fs.createReadStream('./test.eml'))
.getEmailAsHtml()
.then(htmlString => {
fs.writeFileSync('abc.html',htmlString) ;
})
.catch(err => {
console.log(err);
})
It works great. It’s easy. I have a nice little converter so I can just simply view the email messages that I retrieve from my server. No one controls me!! 🤓
Oh, let’s take a look at the node_modules that were installed for this little program:

